﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace An_Im.Extension.Contract
{
    public class VBAExportableCommand : AnImCommandBase
    {
        private string _vbacode = null;

        public VBAExportableCommand(string name, string description, IList<ParaNameValuePair> paralist, CommandExecuteHandler commandExecuteHandler, string vbacode) : base(name, description, paralist, commandExecuteHandler)
        {
            VBAExportable = true;
            _vbacode = vbacode;
        }

        public override string ExportVBACode(IList<ParaNameValuePair> paralist)
        {

            if (paralist == null && DefaultParas == null)
                return _vbacode;

            else if (paralist == null && DefaultParas != null)
            {
                var arr = (from para in DefaultParas select para.Value).ToArray();
                return string.Format(_vbacode, arr);
            }
            else
            {
                var arr = (from para in paralist select para.Value).ToArray();
                return string.Format(_vbacode, arr);
            }
        }

    }
}
